﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations.FormBase;
using STLGROUP.Layers.Common;

namespace QuanLyBanHang
{
    /// <summary>
    /// CF006 - Danh Muc Phong Ban
    /// </summary>
    public partial class CF006 : frmCatalogBase
    {

        #region Member variables

        private static int _idPhongBan;

        #endregion

        #region Constructors

        public CF006()
        {
            InitializeComponent();
        }

        #endregion

        #region Protected Methods

        protected override void LoadData()
        {
            this._bindingSource.DataSource = Cache.Context.DM_PhongBan;
            dgvPhongBan.DataSource = _bindingSource;

            base.LoadData();
        }

        protected override void AddDataBinding()
        {
            txtMaPhongBan.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "IDPhongBan", true);
            txtTenPhongBan.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "TenPhongBan", true);
            txtGhiChu.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "GhiChu", true);

            cboTenTruongPhong.DataSource = Cache.Context.DT_NhanVien;
            cboTenTruongPhong.ValueMember = "IDNhanVien";
            cboTenTruongPhong.DisplayMember = "TenDayDu";
            cboTenTruongPhong.DataBindings.Add(Const.BIND_SELECTED_VALUE, _bindingSource, "IDTruongPhong", true);

            colTenTruongPhong.DataSource = Cache.Context.DT_NhanVien;
            colTenTruongPhong.ValueMember = "IDNhanVien";
            colTenTruongPhong.DisplayMember = "TenDayDu";

            base.AddDataBinding();
        }

        #endregion

        #region Public Methods

        public static int GetIDPhongBan()
        {
            return _idPhongBan;
        }

        #endregion

        #region Events

        private void dgvPhongBan_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void dgvPhongBan_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 4)
                {
                    _idPhongBan = int.Parse(dgvPhongBan.CurrentRow.Cells[0].Value.ToString());

                    this.Close();
                }
                else
                {
                    _idPhongBan = 0;
                }
            }
            catch
            {
                _idPhongBan = 0;
            }
        }

        #endregion

    }
}
